//
//  HMCarouselViewController.m
//  HMDemo
//
//  Created by mengxiangyu on 2017/7/7.
//  Copyright © 2017年 mengxiangyu. All rights reserved.
//

#import "HMCarouselViewController.h"
#import "HMCarousel.h"
@interface HMCarouselViewController ()<HMCarouselDelegate>
@property (strong, nonatomic) HMCarousel *carousel;

@property (strong, nonatomic) NSArray *dataArray;

@end

@implementation HMCarouselViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    [self.view addSubview:view];
    
    _dataArray = @[@"0", @"1", @"2", @"3"];
    
    HMCarousel *carousel = [[HMCarousel alloc] initWithFrame:CGRectMake(0, 64, HM_WIDTH, 200)];
    [self.view addSubview:carousel];
    self.carousel = carousel;
    [carousel showCarouselRect:CGRectMake(0, 0, HM_WIDTH, HM_HEIGHT) carouselCount:_dataArray.count target:self repeat:NO];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 40, 40)];
    btn.backgroundColor = [UIColor redColor];
    [btn setTitle:@"10" forState:(UIControlStateNormal)];
    [self.view addSubview:btn];
    [[btn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(id x) {
        _dataArray = @[@"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];
        self.carousel.carouselCount = _dataArray.count;
    }];
    
}

- (void)setContentView:(HMScrollViewItem *)view index:(NSInteger)index {
    
    //    view.backgroundColor = [UIColor yellowColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    label.font = [UIFont systemFontOfSize:50];
    label.text = _dataArray[index];
    label.backgroundColor = [UIColor grayColor];
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    
    view.contentView = label;
    
}

- (void)setItemView:(HMCollectionViewItem *)view index:(NSInteger)index {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    label.font = [UIFont systemFontOfSize:50];
    label.text = _dataArray[index];
    label.backgroundColor = [UIColor grayColor];
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    
    view.itemContentView = label;
}

- (void)touchCarouselIndex:(NSInteger)index {
    XYLog(@"%s--%ld",__func__, index);
}

- (void)scrollToIndex:(NSInteger)index {
    NSLog(@"%s--%ld",__func__, index);
}

@end
